<!--  -->
<template>
    <div>
        <!-- 面包屑存放 -->
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>权限管理</el-breadcrumb-item>
            <el-breadcrumb-item>角色列表</el-breadcrumb-item>
        </el-breadcrumb>
        <el-card>
            <el-button type="primary">添加用户</el-button>
            <el-table :data="rolesList" stripe border>
                <!-- 展开列 -->
                <el-table-column type="expand">
                    <template slot-scope="scope">
                        <el-row :class="['bdbottom', i1===0 ? 'bdtop':'','vcenter']"
                            v-for="(item1,i1) in scope.row.children" :key="item1.id">
                            <el-col :span="5">
                                <el-tag>{{item1.authName}}</el-tag>
                                <i class="el-icon-caret-right"></i>
                            </el-col>
                            <el-col :span="19">
                                <el-row :class="[i2===0 ? 'bdtop':'','vcenter']" v-for="(item2,i2) in item1.children"
                                    :key="item2.id">
                                    <el-col :span="6">
                                        <el-tag type="success">{{item2.authName}}</el-tag>
                                        <i class="el-icon-caret-right"></i>
                                    </el-col>
                                    <el-col :span="18">
                                        <el-tag type="warning" v-for="item3 in item2.children" :key="item3.id" closable
                                            @close="colseTagDelete">
                                            {{item3.authName}}</el-tag>

                                    </el-col>
                                </el-row>
                            </el-col>
                        </el-row>
                        <pre>
                        {{scope.row.children}}
                        </pre>
                    </template>
                </el-table-column>
                <!-- 索引列 -->
                <el-table-column type="index" label="#">
                </el-table-column>
                <el-table-column prop="roleName" label="角色名称">
                </el-table-column>
                <el-table-column prop="roleDesc" label="角色描述">
                </el-table-column>

                <el-table-column label="操作" width="300px">
                    <template>
                        <!--  {{scope}} slot-scope="scope" -->
                        <el-button type="primary" icon="el-icon-edit" size="mini">
                        </el-button>
                        <el-button type="danger" icon="el-icon-delete" size="mini">
                        </el-button>
                        <el-tooltip effect="dark" content="分配角色" placement="top" :enterable="false">
                            <el-button type="warning" icon="el-icon-setting" size="mini"></el-button>
                        </el-tooltip>

                    </template>
                </el-table-column>
            </el-table>
        </el-card>
    </div>
</template>

<script>
    export default {
        name: 'Roles',
        data() {
            return {
                rolesList: []
            }
        },
        created() {
            this.getRolesList();
        },
        methods: {
            async getRolesList() {
                const { data: res } = await this.$http.get(`roles`)
                if (res.meta.status !== 200) {
                    return this.$message.error(res.meta.msg)
                }

                this.rolesList = res.data
            },
            async colseTagDelete() {
                const deleteResult = await this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).catch(err => err)
                if (deleteResult !== confirm) {
                    console.log('用户取消了删除')
                }
            }
        }
    }
</script>
<style lang="scss" scoped>
    .el-tag {
        margin: 7px;
    }

    .bdtop {
        border-top: 1px solid #eee;
    }

    .bdbottom {
        border-bottom: 1px solid #eee;
    }

    .vcenter {
        display: flex;
        align-items: center;
    }
</style>